//@author A0121492M

import java.util.Date;

public class Task implements Comparable<Task> {
        // Constants
        public static final int EMPTY_ID = -1;
        public static final String EMPTY_STRING = null;
        public static final Date EMPTY_TIME = null;
        
        public int id = EMPTY_ID;
        public String title = EMPTY_STRING;
        public Date startTime = EMPTY_TIME;
        public Date endTime = EMPTY_TIME;
        public String place = EMPTY_STRING;
        public String description = EMPTY_STRING;
        public String project = EMPTY_STRING;
        public boolean isDone = false;
          
        @Override
        public boolean equals(Object t1) {
        	Task t = (Task)t1;
    		if (this.id == t.id) {
    			return true;
    		} else {
    			return false;
    		}
    	}

		public int compareTo(Task o) {
			Date t1s = this.startTime;
			Date t1e = this.endTime;
			Date t2s = o.startTime;
			Date t2e = o.endTime;
			if (t1s != EMPTY_TIME && t1e != EMPTY_TIME && t2s != EMPTY_TIME && t2e != EMPTY_TIME) {
				return t1s.compareTo(t2s);
			} else if (t1s != EMPTY_TIME && t1e != EMPTY_TIME && t2s != EMPTY_TIME && t2e == EMPTY_TIME) {
				return t1s.compareTo(t2s);
			} else if (t1s != EMPTY_TIME && t1e != EMPTY_TIME && t2s == EMPTY_TIME && t2e != EMPTY_TIME) {
				return t1s.compareTo(t2e);
			} else if (t1s != EMPTY_TIME && t1e == EMPTY_TIME && t2s != EMPTY_TIME && t2e != EMPTY_TIME) {
				return t1s.compareTo(t2s);
			} else if (t1s != EMPTY_TIME && t1e == EMPTY_TIME && t2s != EMPTY_TIME && t2e == EMPTY_TIME) {
				return t1s.compareTo(t2s);
			} else if (t1s != EMPTY_TIME && t1e == EMPTY_TIME && t2s == EMPTY_TIME && t2e != EMPTY_TIME) {
				return t1s.compareTo(t2e);
			} else if (t1s == EMPTY_TIME && t1e != EMPTY_TIME && t2s != EMPTY_TIME && t2e != EMPTY_TIME) {
				return t1e.compareTo(t2s);
			} else if (t1s == EMPTY_TIME && t1e != EMPTY_TIME && t2s != EMPTY_TIME && t2e == EMPTY_TIME) {
				return t1e.compareTo(t2s);
			} else if (t1s == EMPTY_TIME && t1e != EMPTY_TIME && t2s == EMPTY_TIME && t2e != EMPTY_TIME) {
				return t1e.compareTo(t2e);
			} else if (t1s == EMPTY_TIME && t1e == EMPTY_TIME && t2s != EMPTY_TIME && t2e == EMPTY_TIME) {
				return 1;
			} else if (t1s == EMPTY_TIME && t1e == EMPTY_TIME && t2s == EMPTY_TIME && t2e != EMPTY_TIME) {
				return 1;
			} else if (t1s != EMPTY_TIME && t1e == EMPTY_TIME && t2s == EMPTY_TIME && t2e == EMPTY_TIME) {
				return -1;
			} else if (t1s == EMPTY_TIME && t1e != EMPTY_TIME && t2s == EMPTY_TIME && t2e == EMPTY_TIME) {
				return -1;
			} else if (t1s != EMPTY_TIME && t1e != EMPTY_TIME && t2s == EMPTY_TIME && t2e == EMPTY_TIME) {
				return -1;
			} else if (t1s == EMPTY_TIME && t1e == EMPTY_TIME && t2s != EMPTY_TIME && t2e != EMPTY_TIME) {
				return 1;
			} else if (t1s == EMPTY_TIME && t1e == EMPTY_TIME && t2s == EMPTY_TIME && t2e == EMPTY_TIME) {
				return 0;
			}
			return 0;
		}
		
		public Task clone(){  
		    Task clone = new Task();
		    clone.id = this.id;
		    clone.title = this.title;
		    clone.startTime = this.startTime;
		    clone.endTime = this.endTime;
		    clone.place = this.place;
		    clone.project = this.project;
		    clone.description = this.description;
		    clone.isDone = this.isDone;
		    return clone;
		}

		public boolean containsKeyword(String keyword) {
			if (this.title != EMPTY_STRING) {
				if (this.title.toLowerCase().contains(keyword)) {
					return true;
				}
			} 
			if (this.place != EMPTY_STRING) {
				if (this.place.toLowerCase().contains(keyword)) {
					return true;
				}
			}
			if (this.description != EMPTY_STRING) {
				if (this.description.toLowerCase().contains(keyword)) {
					return true;
				}
			}
			if (this.project != EMPTY_STRING) {
				if (this.project.toLowerCase().contains(keyword)) {
					return true;
				}
			}
			return false;
		}
}